<template>
    <xh-pages>
        <u-picker :show="levelShow" :columns="levelColumns" @confirm="levelConfirm" @cancel="levelShow = false"
            keyName="label" />
        <u-picker :show="sortShow" :columns="sortColumns" @confirm="sortConfirm" @cancel="sortShow = false"
            keyName="label" />
        <view class="tabs">
            <view class="item" @tap="sortShow = true">
                <view class="text">排序方式</view>
                <u-icon name="arrow-down" size="16"></u-icon>
            </view>
            <view class="item" @tap="levelShow = true">
                <view class="text">旗下层级</view>
                <u-icon name="arrow-down" size="16"></u-icon>
            </view>
        </view>
        <view class="team-list" v-if="datalist.length">
            <view class="item" v-for="(item, index) in datalist" :key="index">
                <view class="user">
                    <image :src="item.avatar" class="avatar"></image>
                    <view class="info">
                        <view class="info-item">
                            <!-- <u-icon name="woman" size="18" color="#2979ff"></u-icon> -->
                            <text>{{ item.nickname }}</text>
                        </view>
                        <view class="info-item">
                            <u-icon name="rmb-circle" color="#F5D371"></u-icon>
                            <text>{{ item.amount_total }}</text>
                        </view>
                    </view>
                </view>
                <view class="icon">
                    <view class="time">{{ item.join_time }}</view>
                </view>
            </view>
        </view>
    </xh-pages>
</template>

<script setup lang="ts">
const levelShow = ref(false)
const levelActive = ref('dealer_one')
const levelColumns = reactive([
    [
        {
            label: '我的直推',
            value: 'dealer_one'
        },
        {
            label: '我的二级',
            value: 'dealer_two'
        },
        {
            label: '我的三级',
            value: 'dealer_three'
        },
    ]
]);
const sortShow = ref(false)
const sortActive = ref('desc')
const sortColumns = reactive([
    [
        {
            label: '倒序',
            value: 'desc'
        },
        {
            label: '正序',
            value: 'asc'
        },
    ]
]);

const datalist = ref<{
    avatar: string
    nickname: string
    join_time:string
    amount_total:string
}[]>([]);

// 点击确认
const sortConfirm = (e:any) => {
    const value = e?.value[0].value ?? ''
    sortActive.value = value;
    getList()
    sortShow.value = false;
}
// 点击确认
const levelConfirm = (e: any) => {
    const value = e?.value[0].value ?? ''
    levelActive.value = value;
    getList()
    levelShow.value = false;
}
const getList = () => {
    const params = {
        level: levelActive.value,
        sort: sortActive.value
    }
    uni.$u.http.get('DealerTeam/index', {params}).then((res: any) => {
        datalist.value = res.data
    })
}
onLoad(() => {
    getList()
})
</script>

<style lang="scss" scoped>
.tabs {
    display: flex;
    background: #fff;

    .item {
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 30rpx 0;
        font-size: 28rpx;

        .text {
            padding: 0 10rpx;
        }
    }
}

.team-list {
    display: flex;
    flex-direction: column;
    margin-top: 30rpx;

    .item {
        display: flex;
        justify-content: space-between;
        padding: 30rpx;
        background: #fff;
        border-bottom: 1px solid #f1f1f1;

        .user {
            display: flex;

            .avatar {
                width: 90rpx;
                height: 90rpx;
                border-radius: 50%;
            }

            .info {
                padding-left: 10rpx;
                font-size: 28rpx;
                display: flex;
                flex-direction: column;
                justify-content: center;

                .info-item {
                    display: flex;
                }
            }
        }

        .icon {
            display: flex;
            flex-direction: column;
            justify-content: center;
            font-size: 28rpx;

            .level {
                padding-right: 10rpx;
            }

            .time {}
        }
    }
}</style>